package com.base.controller.utils.CZB;

import com.base.helper.WebHelper;
import com.base.po.czb_sdk.CZBUtil;
import com.beust.jcommander.internal.Maps;

import java.util.Date;
import java.util.Map;

public class CZBBillingUtil {

    private static final String APP_KEY = "suibiandah51.0";
    private static final String APP_SECRET = "12ba273f41c9ac54e7303c0af5d80136";
    private static final String PLATFORMTYPE = "92656163";
    private static final String PAY_CODE = "1054";

    private static final String APP_KEY_API = "suibianda1.0";
    private static final String APP_SECRET_API = "16bc2edcaed84b3eaab079a16a4eeb54";
    private static final String PLATFORMTYPE_API = "92654416";
    private static final String PAY_CODE_API = "1054";
    /**
     * 正式环境
     */
    private static final String FORMAL_CONTEXT = "https://mcs.czb365.com/services/v3/";
    /**
     * 测试环境
     */
    private static final String TEST_CONTEXT = "https://test-mcs.czb365.com/services/v3/";

    /**
     * 使用环境
     */
    private static final String USE_CONTEXT = FORMAL_CONTEXT;
    /**
     * 接口
     */
    //未开票
    private static final String CZB_BILLINGALL = USE_CONTEXT + "invoice/gasQueryListWithPage";
    //开票
    private static final String CZB_BILLING_GET = USE_CONTEXT + "invoiceThird/gasInsert";
    //已开票
    private static final String CZB_BILLING_ALLREADY=USE_CONTEXT+"invoiceThird/queryInvoiceListWithPage";
    /**
     * @Date: 2020/4/17 10:55
     * @Description: 获取未开票信息
     */
    public static String getBilling(Integer pageSize, Integer pageIndex, String mobile) {
        String token = CZBTokenUtils.getNowToken(mobile);
        Map<String, Object> map = Maps.newHashMap();
        map.put("pageSize", pageSize);
        map.put("pageIndex", pageIndex);
        map.put("orderSource", PLATFORMTYPE);
        map.put("token", token);
        map.put("timestamp", new Date().getTime());
        map.put("app_key", APP_KEY);
        String sign = CZBUtil.getSign(map, APP_SECRET);
        String param = CZBUtil.getParam(map, sign);
        String result = WebHelper.PostData(CZB_BILLINGALL, param, null, null);
        return result;
    }

    /**
     * @Date: 2020/4/17 10:55
     * @Description: 执行开票,邮件发送
     *
     * @invoiceContent 开票类型 1:油票 2:气票 3:电票
     * @title 0 公司 1 个人
     * @orders 订单号以字符串分割
     * JS00000179920041310tYw5
     */
    public static String BillingGet(String mobile,Integer title, String buyerTaxNo, String buyerName,String buyerAddressPhone,String buyerBankAccount,String buyerEmail,String orders,Integer invoiceContent) {
        Long date=new Date().getTime();
        String token = CZBTokenUtils.getNowToken1(mobile,date);
        Map<String, Object> map = Maps.newHashMap();
        map.put("title", 1);
        map.put("buyerName", "pqtomato");
        map.put("buyerEmail", "897101935@qq.com");
        map.put("orders", "JS00000179920041310tYw5");
        map.put("invoiceContent", 1);
        map.put("orderSource", PLATFORMTYPE);
        map.put("token", token);
        map.put("timestamp",date);
        map.put("app_key", APP_KEY);
//        map.put("buyerTaxNo", buyerTaxNo);
//        map.put("buyerAddressPhone", buyerAddressPhone);
//        map.put("buyerBankAccount", buyerBankAccount);
        String sign = CZBUtil.getSign(map, APP_SECRET);
        String param = CZBUtil.getParam(map, sign);
        String result = WebHelper.PostData(CZB_BILLING_GET, param, null, null);
        return result;
    }

    /**
     * @Date: 2020/4/17 10:55
     * @Description: 获取已开票信息
     */
    public static String getBillingAllready(Integer pageSize, Integer pageIndex, String mobile) {
        String token = CZBTokenUtils.getNowToken(mobile);
        Map<String, Object> map = Maps.newHashMap();
        map.put("pageSize", pageSize);
        map.put("pageIndex", pageIndex);
        map.put("orderSource", PLATFORMTYPE);
        map.put("token", token);
        map.put("timestamp", new Date().getTime());
        map.put("app_key", APP_KEY);
        String sign = CZBUtil.getSign(map, APP_SECRET);
        String param = CZBUtil.getParam(map, sign);
        String result = WebHelper.PostData(CZB_BILLING_ALLREADY, param, null, null);
        return result;
    }

}
